$(window).load(function(){
	
	init();
	onResize();
	$(window).resize(onResize);
});


function init(){
	
	//make (sub-)listitems sortable
	$("#list .sublist").sortable({axis: "y", connectWith: "#list"});
	$("#list .sublist").disableSelection();
	
	$("#list").sortable({axis: "y", connectWith: "#list .sublist"});
	$("#list").disableSelection();
	
	//hide footer on pageload
	$("#submitLinkForm").hide();
	
	//hide login-form
	$("#drop_down_menu").hide();
	
	//hide sublists in navigation
	$(".folder").children(".sublist").hide();
	
	//hide elements when not logged in
	$(".login_on").hide();
	
	//select subreddit
	$("#list li").click(function(){
		if(!$(this).hasClass("folder")){
			$("#list .selectedlistitem").removeClass("selectedlistitem");
			$(this).addClass("selectedlistitem");
		}
	});
}


function onResize(){
	
	//resize NAVIGATION and LISTHEIGHT
	var windowheight = $(window).height();
	var headerheight = $("header").outerHeight();		//header-height without margin
	var footerheight = 0;
	if($("footer").is(":visible")){
		footerheight = $("footer").outerHeight(true);	//footer-height inclusive margin
		$("footer").outerWidth($(window).outerWidth());
	}
	var navheight = windowheight-headerheight-footerheight;
	
	//set navigation height
	$("nav").height(navheight);
	
	var folderoptionsheight = 0;
	if($("#folderoptions").is(":visible")){
		folderoptionsheight = $("#folderoptions").outerHeight(true)
	}
	
	var listheight = $("nav").height()-$("#search").outerHeight(true)-folderoptionsheight;
	//set listheight and scrollbar height
	$("#subredditlist").height(listheight);
	//$("#bar").height(listheight-5);
	
	//resize width of CONTENT-HEADER	
	var contentwidth = $(window).outerWidth()-$("nav").outerWidth();
	$("#content").width(contentwidth);
	$("#content").height(navheight);
	
	setScrollbar();
}
